package scala.test_tuples

/**
 * @author 黄海峰 2021/4/15 18:45
 * */
object DeanTest {
  def main(args: Array[String]): Unit = {
    val ingredient = ("sugar", 25)
    println(ingredient._1)
    println(ingredient._2)
    println("======================>")

    // 原则的参数模型匹配
    val (name, quantity) = ingredient
    println(name)
    println(quantity)
    println("======================>")

    val planets =
      List(("Mercury", 57.9), ("Venus", 108.2), ("Earth", 149.6),
        ("Mars", 227.9), ("Jupiter", 778.3))
    planets.foreach {
      case ("Earth", distance) =>
        println(s"Our planet is $distance million kilometers from the sun")
      case (_, distance) => println("condition is not Earth 【%s】".format(distance))
      case _ =>
    }
    println("======================>")

    val numPairs = List((2, 5), (3, -7), (20, 56))
    for ((a, b) <- numPairs) {
      println(a * b)
    }
  }
}

/**
 * In Scala,
 * a tuple is a value that contains a fixed number of elements,
 * each with its own type. Tuples are immutable.
 *
 * tuples are especially handy for returning multiple values from a method.
 */
